<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/9/3
  Time: 18:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/laypage.css">
    <script src="js/vue/vue.min.js"></script>
    <script src="js/jquery/jquery.min.js"></script>
    <script src="js/laypage/laypage.js" charset="utf-8"></script>
    <script src="js/layer/layer.js" charset="utf-8"></script>
    <script src="js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="js/jquery.validation/1.14.0/messages_zh.min.js"></script>
</head>
<body>
<div class="container">
    <form id="addUserForm">
        <br/>
        <div class="form-group">
            <label for="username">用户名称：</label>
            <input type="text" class="form-control" id="username" name="name" placeholder="输入名称">
        </div>

        <div class="form-group">
            <label for="password">用户密码：</label>
            <input type="password" class="form-control" id="password" name="password" placeholder="输入密码">
        </div>

        <div class="form-group">
            <label for="phone">手机：</label>
            <input type="text" class="form-control" id="phone" name="phone" placeholder="输入手机号">
        </div>

        <%--<div class="form-group">--%>
            <%--<label for="role">角色：</label>--%>
            <%--<input type="text" class="form-control" id="role" name="role" placeholder="输入角色">--%>
        <%--</div>--%>

        <div class="form-group">
            <label for="email">邮箱：</label>
            <input type="text" class="form-control" id="email" name="email" placeholder="输入邮箱">
        </div>

        <%--<div class="form-group">--%>
            <%--<label for="userage">用户年龄：</label>--%>
            <%--<input type="text" class="form-control" id="userage" name="userage" placeholder="输入年龄">--%>
        <%--</div>--%>

        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">提交</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
</body>
</html>
<script>
    var addUser=function(){
        if (!check().form()) {
            return ;
        }
        $.ajax({
            type:"GET",
            url:"addUser",
            dataType:"json",
            data:{
                name: $("#username").val(),
                password: $("#password").val(),
                phone: $("#phone").val(),
                email: $("#email").val(),
            },
            success:function () {
                closeIframe();

            }
        });
    };

    $("#saveBtn").click(function () {
        addUser();
    });

    //关闭窗口
  var closeIframe=function(){
      var index = parent.layer.getFrameIndex(window.name);
      parent.getUserPageList();
     parent.layer.close(index);
  };
    $("#cancelBtn").click(function () {
       closeIframe();
    });



    //校验数据是否填了
    function check() {
        return $("#addUserForm").validate({
            rules: {
                name: {
                    required: true
                },
                password: {
                    required: true
                },
                phone: {
                    required: true
                },
                email: {
                    required: true
                }

            },

            messages: {
                name: {
                    required: ""
                },
                password: {
                    required: ""
                },
                phone: {
                    required: ""
                },
                email: {
                    required: ""
                }
            }
        });
    }
</script>
